<?php
namespace app\app\util;
use think\cache\driver\Redis;

// session前缀
define('SESSION_PREFIX', 'wc:session:');
// 默认过期时间
define('SESSIONOVERDATETIME', 5*60);
// redis驱动session类
class SessionUtils{
    public static function set($key,$value,$overdatetime=SESSIONOVERDATETIME){
        $redis = new Redis(['host'=>config('REDIS_HOST'),'password'=>config('REDIS_AUTH')]);
        if($redis->has(SESSION_PREFIX.$key)){
            $redis->rm(SESSION_PREFIX.$key);
        }
        $redis->set(SESSION_PREFIX.$key,$value,$overdatetime);
        return true;
    }


    public static function get($key){
        $redis = new Redis(['host'=>config('REDIS_HOST'),'password'=>config('REDIS_AUTH')]);
        if($redis->has(SESSION_PREFIX.$key)){
            return $redis->get(SESSION_PREFIX.$key);
        }else{
            return false;
        }
    }
}
